<template>
  <f7-page>
    <f7-navbar>
      <f7-nav-left></f7-nav-left>
      <f7-nav-title>
        <div class="segmented segmented-raised">
          <a class="button tab-link" @click="workerBtn('worker')" :class="{'tab-link-active':btnType=='worker'}">同事</a>
          <a class="button tab-link" @click="workerBtn('customer')" :class="{'tab-link-active':btnType=='customer'}">客户</a>
        </div>
      </f7-nav-title>
      <f7-nav-right><f7-link href="/mine/invite/">邀请</f7-link></f7-nav-right>
    </f7-navbar>
    <f7-toolbar>
      <tab isActive4="true" />
    </f7-toolbar>

    <!--<f7-row no-gutter>
      <f7-col width="80">
        <f7-icon f7="search_strong" class="search_img"></f7-icon>
        <input type="text" placeholder="搜索联系人" class="Please_enter">
      </f7-col>
      <f7-col width="20">
        <f7-button class="search">搜索</f7-button>
      </f7-col>
    </f7-row>-->

   <!-- <f7-block-title class="text-align-center">
      <f7-col class="text-red text_top">认证企业审核中</f7-col>
      <f7-col class="text-red">联系秘书急速通过</f7-col>
      <div class="menu-info-company">
        <img src="../../assets/img/infor-face2.png" class="img-circle">
        <h4></h4>
        <h4 class="text-black">在线秘书</h4>
        <f7-icon f7="phone_fill" class="phone"></f7-icon>
      </div>
      <h4 class="text-gray">或</h4>
      <div class="menu-info-company">
        <span class="text-gray">修改资料重新认证</span>
      </div>
    </f7-block-title>-->


<!--同事-->
    <div v-show="btnType=='worker'" >
      <f7-list media-list>
        <f7-list-item @click="jtBtn()">
          <f7-icon f7="down" class="add" v-show="jtType=='opened'"></f7-icon>
          <f7-icon f7="right" class="add" v-show="jtType=='closed'"></f7-icon>
          <h2 class="new_txt">全部
            <span>({{colleague.length}})</span>
          </h2>
        </f7-list-item>

        <f7-list-item v-for="item in colleague" v-show="jtType=='opened'">
          <template v-if="item.status">
            <img slot="media" round src="../../assets/img/infor-face.png" width="44"  @click="go('/mine/personalPage/',{personalid:item._id})"/>
            <div class="item-title-row" @click="go('/mine/personalPage/',{personalid:item._id})">
              <div class="item-title">{{item.real_name?item.real_name:'无名'}}</div>
              <div class="item-after">{{item.role|roleAll()}}</div>
            </div>
          </template>
          <template v-if="!item.status">
            <img slot="media" round src="../../assets/img/infor-face.png" width="44" />
            <div class="item-title-row">
              <div class="item-title">{{item.real_name?item.real_name:'无名'}}<span style="color: red;font-size: 12px">已邀请，待上线</span></div>
              <div class="item-after">{{item.role|roleAll()}}</div>
            </div>
          </template>
        </f7-list-item>

      </f7-list>

      <!--<f7-block>
        <f7-link @click="$f7router.navigate('/addGroup/')">
          <f7-icon f7="add_round_fill" class="add"></f7-icon>
          <h2 class="new_txt">新建分组</h2>
        </f7-link>
      </f7-block>-->
    </div>
<!--客户-->
    <div v-show="btnType=='customer'">
      <div>
        <ul class="role-type">
           <li @click="goodsBtn('goods')" :class="{'tab-active-btn':gsBtnType=='goods'}">货源方</li>
           <li @click="goodsBtn('driver')" :class="{'tab-active-btn':gsBtnType=='driver'}">司机方</li>
        </ul>


      </div>
      <!--货源方-->
      <div v-show="gsBtnType=='goods'">
        <f7-list media-list>
          <f7-list-item @click="jtBtn()">
            <f7-icon f7="down" class="add" v-show="jtType=='opened'"></f7-icon>
            <f7-icon f7="right" class="add" v-show="jtType=='closed'"></f7-icon>
            <h2 class="new_txt">全部
              <span>({{customerInfo.length}})</span>
            </h2>
          </f7-list-item>

          <f7-list-item v-for="item in customerInfo" v-show="jtType=='opened'">
             <img slot="media" round src="../../assets/img/infor-face.png" width="44" class="infor-face"/>
            <f7-link @click="go('/relationGsDtl/',{goodsid:item._id})">
              <div class="item-title-row">
                <div class="item-title Name_title">
                  {{item.real_name}}   <span class="text-gray">{{item.company_name}}</span>
                  <span v-if="item.verify_phase=='SUCCESS'"><img src='../../assets/img/label-v.png' class="label-v"></span>
                </div>
                <div class="item-after" v-if="item.status">
                  <img src='../../assets/img/complete.png' class="complete">
                </div>
                <div class="item-after" v-if="item.friend">
                        <img src='../../assets/img/friend.png' class="complete">
                  </div>
              </div>
            </f7-link>
          </f7-list-item>
        </f7-list>
      </div>
      <!--司机方-->
      <div v-show="gsBtnType=='driver'">
        <f7-list media-list>
          <f7-list-item @click="jtBtn()">
            <f7-icon f7="down" class="add" v-show="jtType=='opened'"></f7-icon>
            <f7-icon f7="right" class="add" v-show="jtType=='closed'"></f7-icon>
            <h2 class="new_txt">全部
              <span>({{goodsInfo.length}})</span>
            </h2>
          </f7-list-item>
          <f7-list-item v-for="item in goodsInfo" v-show="jtType=='opened'">
             <img slot="media" round src="../../assets/img/infor-face.png" width="44" />
            <f7-link @click="$f7router.navigate('/relationDrDtl/'+item._id)">
              <div class="item-title-row">
                <div class="item-title">
                  {{item.real_name}}
                </div>
                <div class="item-after" v-if="item.status">
                  <img src='../../assets/img/complete.png' class="complete">
                </div>
                <div class="item-after" v-if="item.friend">
                  <img src='../../assets/img/friend.png' class="complete">
                </div>
              </div>
            </f7-link>
          </f7-list-item>
        </f7-list>
      </div>
    </div>

  </f7-page>
</template>

<script>
import tab from '../../components/tab.vue'
import F7Block from 'framework7-vue/src/components/block'
import F7Link from "framework7-vue/src/components/link";

export default {
  name: 'app',
  data () {
    return {
      colleague:'',
      customerInfo:'',
      goodsInfo:'',
      unGoodsList:'',
        carList:'',
        zdyList:'',
        groupId:'',
      btnType:"worker",
      gsBtnType:'goods',
        jtType:'opened'
    }
  },
  components: {
    F7Link,
    F7Block,
    tab
  },
  methods: {
    goConnect (item) {
      let param = {
        userId: item._id,
        userRole: item.role,
        role: this.Storage.get('user').user.role
      }
      window.cordova.plugins.yimPlugin.chat(param.userId, 0, param.role, param.userRole, '0xA2A2F0', function (success) {
        console.log('云信Chat成功', success)
      }, function () {
        console.log('云信Chat失败')
      })
    },
      //点击同事或者客户改变内容
    workerBtn(type){
        this.btnType = type
    },
      //点击货源方或者司机方改变内容
      goodsBtn(type){
        this.gsBtnType = type
      },
      //收起展开列表
      jtBtn(){
        if(this.jtType == 'closed'){
            this.jtType = 'opened'
        }else {
            this.jtType = 'closed'
        }
      },
      //获取客户列表数据
      async getCustomer () {
        let param={page:1,type:"PURCHASE_1"}
            this.customerInfo = (await this.AccountService.getRelationCustomer(param)).data.data.list
      },
      async getGoods(){
        let param ={page:1,type:"DRIVER_1"}
          this.goodsInfo = (await this.AccountService.getRelationCustomer(param)).data.data.list
      },
      //未分组司机列表
      async getUnDrGoods(){
          this.unGoodsList = (await this.AccountService.getUnDrlist()).data.data.list
      },
      //司机列表
      async getCarList(){
          let param ={type:"DRIVER"}
          this.carList = (await this.AccountService.getCarGroup(param)).data.data
      },
      //自定义列表
      async getZdyDrList(){
          let param = { group_id: this.groupId}
          this.zdyList = (await this.AccountService.getZdyList(param))

      }
  },
  async mounted () {
    let param = { page: 1 }
    let getColleagueRes = await this.AccountService.getColleague(param)
    this.colleague = getColleagueRes.data.data.list

    this.getCustomer()
      this.getGoods()
      this.getUnDrGoods()
      this.getCarList()
      this.getZdyDrList()
  }
}
</script>

<style scoped>
.role-type {
    width: 100%;
    height: 35px;
    padding:0px;
    margin: 10px 0px;
}
.role-type li.active {
    color: #000;
}

.tab-active-btn{
  color: black !important;
}

.role-type li {
    float: left;
    padding: 12px 18px 12px 18px;
    color: #999;
}
.infor-face{
      max-width: 40px !important;
    max-height: 40px !important;
    width: 100%;
    height: 100%;
}
.Name_title{
  font-size: 14px !important;
    font-weight:initial !important;
    color: #333 !important;

}
.label-v {
  width: 24px;
  height: 14px;
  vertical-align: text-bottom;
  vertical-align: middle;
}
.complete{
  width: 24px;
  height: 14px;
  vertical-align: text-bottom;
  vertical-align: middle;
  margin: 0 2px;
}


.ios a {
  color: #333;
  display: inline-block;
  width: 100%;
}

.ios .list {
  margin-top: 0;
  margin-bottom: 0;
}
ol, ul {
    list-style: none;
}
.ios .page {
  background: #fff;
}
.ios .color-theme-white .button.tab-link-active {
  color: #a2a2f0;
}
.row {
  position: relative;
  background: #f5f5f5;
  border-bottom: 1px solid #f5f5f5;
  padding: 10px;
  height: 35px;
}

.ios .row .col-80 {
  background: #fff;
  border-radius: 4px;
  height: 34px;
}

.search {
  background: #fff;
  color: #999 !important;
  border-color: #fff !important;
  font-size: 12px;
  height: 34px !important;
  line-height: 34px !important;
}

.search_img {
  position: absolute;
  font-size: 16px;
  color: #999;
  top: 19px;
  left: 20px;
}

.Please_enter {
  margin-left: 30px;
  width: 80%;
  height: 34px;
}

.ios .invitation {
  border: none;
  color: #fff;
  font-size: 14px;
  width: 60px;
  position: absolute;
  right: 0px;
  top: 8px;
  text-align: right;
}

.text-red {
  color: #db4226;
  font-size: 18px;
  margin: 15px 0px;
}

.text_top {
  margin-bottom: 10px;
}

.menu-info-company {
  width: 42%;
  min-height: 34px;
  line-height: 34px;
  margin: 10px 29%;
  padding-left: 0;
  position: relative;
  padding: 5px 0 5px 10px;
  border: 1px solid #f0f0f0;
  background: #fff;
  border-radius: 25px;
}

.menu-info-company img {
  position: absolute;
  left: 5px;
  top: 6px;
  width: 30px;
  height: 30px;
  border-radius: 100%;
  background: #f0f0f0;
}

.menu-info-company h4 {
  font-family: verdana, 'Hiragino Sans GB', 'Microsoft Yahei', 微软雅黑,
    'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: #333;
    font-weight: 400;
    font-size: 14px;
    margin: 0;
    height: 16px;
    margin-top: -10px;
  }

  .text-black {
    margin-top: 4px !important;
  }

  .phone {
    position: absolute;
    right: 10px;
    top: 10px;
    font-size: 20px;
  }

  .text-gray {
    color: #999;
    margin: 0px;
    font-size: 12px;
  }

  .media-list .item-media img {
    max-width: 48px;
    max-height: 48px;
    border-radius: 50%;
  }

  .ios .media-list .item-title,
  .ios li.media-item .item-title {
    font-size: 16px;
    font-weight: 500;
    color: #000;
    display: initial;
  }

  .ios .list .item-after {
    color: #8e8e93;
    padding-left: 5px;
    font-size: 12px;
  }

  .item-title-row {
    margin-top: 10px;
  }

  .add {
    font-size: 18px;
  }

  .new_txt {
    margin: 0px;
    font-weight: inherit;
    display: inline-block;
    font-size: 14px;
    margin-left: 10px;
    color: #000;
  }

  .new_txt span {
    margin-left: 5px;
  }

  .ios .block {
    margin: 0;
    padding: 0 15px;
    color: #000;
    margin-top: 10px;
  }

  .list li {
    position: initial;
  }

  .ios .button.tab-link-active {
    background: #fff;
    color: #a2a2f0 !important;
  }

  .ios .button {
    border: 1px solid #fff;
    color: #fff;
  }

  .ios .navbar .right {
    margin-left: 10px;
    color: #fff;
    font-size: 14px;
  }

  .ios .segmented .button {
    border-left-width: 1px !important;
  }

  .ios .block-title {
    margin: 10px 15px 10px;
  }
</style>
